﻿using System.Web.Security;

namespace myFinance.Services.Admin
{
	public class RoleService : IRoleService
	{
		private readonly RoleProvider _provider;

		public RoleService()
			: this(null)
		{
		}

		public RoleService(RoleProvider provider)
		{
			_provider = provider ?? Roles.Provider;
		}

		public string[] GetAllRoles()
		{
			return _provider.GetAllRoles();
		}

		public string[] GetUsersInRole(string roleName)
		{
			return _provider.GetUsersInRole(roleName);
		}

		public void RemoveUserFromRole(string userName, string roleName)
		{
			RemoveUsersFromRoles(new[] {userName}, new[] {roleName});
		}

		public void RemoveUsersFromRole(string[] userNames, string roleName)
		{
			RemoveUsersFromRoles(userNames, new[] {roleName});
		}

		public void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
		{
			_provider.RemoveUsersFromRoles(userNames, roleNames);
		}

		public bool DeleteRole(string roleName, bool throwOnPopulatedRole)
		{
			return _provider.DeleteRole(roleName, throwOnPopulatedRole);
		}

		public bool RoleExists(string roleName)
		{
			return _provider.RoleExists(roleName);
		}

		public void CreateRole(string roleName)
		{
			_provider.CreateRole(roleName);
		}

		public bool IsUserInRole(string userName, string roleName)
		{
			return _provider.IsUserInRole(userName, roleName);
		}

		public void AddUserToRole(string userName, string roleName)
		{
			AddUsersToRoles(new[] {userName}, new[] {roleName});
		}

		public void AddUsersToRoles(string[] userNames, string[] roleNames)
		{
			_provider.AddUsersToRoles(userNames, roleNames);
		}
	}
}